package com.jjh.web;

import com.alibaba.fastjson.JSON;
import com.jjh.jhwebserver.annation.WebServlet;
import com.jjh.jhwebserver.context.HttpServlet;
import com.jjh.jhwebserver.context.HttpServletRequest;
import com.jjh.jhwebserver.context.HttpServletResponse;
import com.jjh.web.entiry.User;


@WebServlet(path = "/user")
public class UserServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse respone) {
        String id = request.getPramater("id");
        System.out.println(id);
        respone.setHeader("Content-Type: application/json");
        User user = new User("张三","123");
        respone.write(JSON.toJSONString(user));
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse respone) {

        String body = request.getRequestBody();
        System.out.println(body);

        respone.setHeader("Content-Type: application/json");
        respone.setHeader("Access-Control-Allow-Origin: *");
        respone.setHeader("Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE");
        User user1 = new User("jjh123","123");
        respone.write(JSON.toJSONString(user1));

    }
}
